﻿using System;
using System.Collections.Generic;
using System.Text;
using JEng_Mark_1.Interfaces;
using Microsoft.Xna.Framework;

namespace JEng_Mark_1.SceneObject.SceneGraph
{
    public class JSceneObjectNode : JNode
    {
        private JSceneObject _sceneObject;
        /// <summary>
        /// Get / Set the underlying object of this node
        /// </summary>
        public JSceneObject SceneObject { get { return _sceneObject; } set { _sceneObject = value; } }

        /// <summary>
        /// Construct a node from a scene object
        /// </summary>
        /// <param name="newObject">Object to encapsulate</param>
        public JSceneObjectNode(JSceneObject newObject)
        {
            _sceneObject = newObject;
        }

        /// <summary>
        /// Update underlying object if supported
        /// </summary>
        public override void Update()
        {
            if (SceneObject is IJEngUpdateable)
                ((IJEngUpdateable)SceneObject).Update();
        }

        /// <summary>
        /// Unload underlying object if supported
        /// </summary>
        public override void UnloadContent()
        {
            if (SceneObject is IJEngLoadable)
                ((IJEngLoadable)SceneObject).UnloadContent();
        }

        /// <summary>
        /// Load underlying object if supported
        /// </summary>
        public override void LoadContent()
        {
            if (SceneObject is IJEngLoadable)
                ((IJEngLoadable)SceneObject).LoadContent();
                
        }

        /// <summary>
        /// Draw the underlying object if it is ready to be rendered
        /// </summary>
        /// <param name="gameTime">Timing snapshot</param>
        public override void Draw(GameTime gameTime)
        {
            SceneObject.Draw(gameTime);
            SceneObject.DrawNodesBoundingBox(gameTime);
        }

    }
}
